package com.example.spring.entity;

import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;

import java.util.List;

/**
 * 岗位Entity
 *
 * @author ThinkGem
 * @version 2013-12-05
 */
public class Position extends DataEntity<Position> {

    private static final long serialVersionUID = 1L;
    private Organization office;    // 归属机构
    private String name;    // 岗位名称
    private String code;    // 岗位代码
    private String dataScope;// 数据范围
    private String sysData;        //是否是系统数据
    private String remarks;  //备注
    //	private User user;		// 根据用户ID查询角色列表
//
    // 岗位的机构列表
    private List<Organization> orgList = Lists.newArrayList();

    public Position() {
        super();
        this.dataScope = "8";  //common
    }

    public Position(String id) {
        super(id);
    }

//	public Station(User user) {
//		this();
//		this.user = user;
//	}

    public String getSysData() {
        return sysData;
    }

    public void setSysData(String sysData) {
        this.sysData = sysData;
    }

    public Organization getOffice() {
        return office;
    }

    public void setOffice(Organization office) {
        this.office = office;
    }

    @Length(min = 1, max = 100)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Length(min = 1, max = 100)
    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }


    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getDataScope() {
        return dataScope;
    }

    public void setDataScope(String dataScope) {
        this.dataScope = dataScope;
    }

    public List<Organization> getOrgList() {
        return orgList;
    }

    public void setOrgList(List<Organization> orgList) {
        this.orgList = orgList;
    }

    public List<String> getOrgIdList() {
        List<String> orgIdList = Lists.newArrayList();
        for (Organization org : orgList) {
            orgIdList.add(org.getId());
        }
        return orgIdList;
    }

    public void setOrgIdList(List<String> orgIdList) {
        orgList = Lists.newArrayList();
        for (String orgId : orgIdList) {
            Organization org = new Organization();
            org.setId(orgId);
            orgList.add(org);
        }
    }

    public String getOrgIds() {
        return StringUtils.join(getOrgIdList(), ",");
    }

    public void setOrgIds(String orgIds) {
        orgList = Lists.newArrayList();
        if (orgIds != null) {
            String[] ids = StringUtils.split(orgIds, ",");
            setOrgIdList(Lists.newArrayList(ids));
        }
    }

//	public List<Organization> getOfficeList() {
//		return officeList;
//	}
//
//	public void setOfficeList(List<Organization> officeList) {
//		this.officeList = officeList;
//	}
//
//	public List<String> getOfficeIdList() {
//		List<String> officeIdList = Lists.newArrayList();
//		for (Organization office : officeList) {
//			officeIdList.add(office.getId());
//		}
//		return officeIdList;
//	}
//
//	public void setOfficeIdList(List<String> officeIdList) {
//		officeList = Lists.newArrayList();
//		for (String officeId : officeIdList) {
//			Organization office = new Organization();
//			office.setId(officeId);
//			officeList.add(office);
//		}
//	}
//
//	public String getOfficeIds() {
//		return StringUtils.join(getOfficeIdList(), ",");
//	}
//
//	public void setOfficeIds(String officeIds) {
//		officeList = Lists.newArrayList();
//		if (officeIds != null){
//			String[] ids = StringUtils.split(officeIds, ",");
//			setOfficeIdList(Lists.newArrayList(ids));
//		}
//	}

//	/**
//	 * 获取权限字符串列表
//	 */
//	public List<String> getPermissions() {
//		List<String> permissions = Lists.newArrayList();
//		for (Menu menu : menuList) {
//			if (menu.getPermission()!=null && !"".equals(menu.getPermission())){
//				permissions.add(menu.getPermission());
//			}
//		}
//		return permissions;
//	}
//
//	public User getUser() {
//		return user;
//	}
//
//	public void setUser(User user) {
//		this.user = user;
//	}

}
